package de.tuhh.simsearch.model.persistence.usermgmt.eao.interfaces;

import java.util.List;

import javax.ejb.Local;

import de.tuhh.simsearch.model.persistence.usermgmt.entities.GroupEntity;
import de.tuhh.simsearch.model.persistence.usermgmt.entities.PreferenceEntity;
import de.tuhh.simsearch.model.persistence.usermgmt.entities.RoleEntity;
import de.tuhh.simsearch.model.persistence.usermgmt.entities.UserEntity;

/**
 * This is the interface between UserMgmtEAO and the Controller class UserMgmt. It describes the functions needed in the
 * controller. UserMgmtEAO should implement this interface.
 * 
 * @author SimSearch 1
 * 
 */
@Local
public interface UserMgmtEAOInterface {

  /**
   * Checks the password
   * 
   * @param usrName
   *          name of the user
   * @param pswd
   *          hash of the password
   * @return true if password hash matches, false otherwise
   */
  public boolean checkPassword(String usrName, String pswd);

  /**
   * Generates new user in the database
   * 
   * @param user
   *          user to be added
   * @return true, if operation was successful, false otherwise
   */
  public boolean persistUser(UserEntity user);

  /**
   * Delete user from database
   * 
   * @param userName
   *          name of user to be deleted
   * @return true, if operation was successful, false otherwise
   */
  public boolean deleteUser(String userName);

  /**
   * Delete group from database
   * 
   * @param groupName
   *          name of group to be deleted
   * @return true, if operation was successful, false otherwise
   */
  public boolean deleteGroup(String groupName);

  /**
   * Checks if user name is already in use
   * 
   * @param name
   *          user name to be checked
   * @return true if user name is free, false otherwise
   */
  public boolean isUserNameFree(String name);

  /**
   * Checks if preference name is already in use
   * 
   * @param name
   *          preference name to be checked
   * @return true if preference name is free, false otherwise
   */
  public boolean isPreferenceNameFree(String name, Integer contentId);

  /**
   * Gets a preference entity object.
   * 
   * @param categoryName
   *          the category name of the preference to get
   * @param contentId
   *          the content id of the preference to get
   * @return the preference entity object
   */
  public PreferenceEntity getPreferenceEntity(String categoryName, Integer contentId);

  /**
   * Adds a preference to a user profile
   * 
   * @param userName
   *          name of user
   * @param categoryName
   *          name of the preferred category to be added to profile
   * @param contentId
   *          ID of the preferred content to be added to profile
   * @return true, if operation was successful, false otherwise
   */
  public boolean addPreference(String userName, String categoryName, Integer contentId);

  /**
   * Removes a preference from a user profile
   * 
   * @param userName
   *          name of user
   * @param categoryName
   *          name of category to be removed as a preference
   * @param contentId
   *          ID of content to be removed as a preference
   * @return true, if operation was successful, false otherwise
   */
  public boolean removePreference(String userName, String categoryName, Integer contentId);

  /**
   * Changes a user password
   * 
   * @param userName
   *          name of user
   * @param newpswd
   *          hash of new password
   * @return true, if operation was successful, false otherwise
   */
  public boolean changePassword(String userName, String newpswd);

  /**
   * Creates a group.
   * 
   * @param group
   *          the group to create
   * @return true, if operation was successful, false otherwise
   */
  public boolean persistGroup(GroupEntity group);

  /**
   * Checks if group name already exists.
   * 
   * @param name
   *          name that should be checked
   * @return true, if group name is not already in use, false otherwise
   */
  public boolean isGroupNameFree(String name);

  /**
   * Checks if user is in this group
   * 
   * @param userName
   *          name of user to be checked
   * @param groupName
   *          name of group to be checked
   * @return true, if user is in group, false otherwise
   */
  public boolean isUserInGroup(String userName, String groupName);

  /**
   * Adds a user to a group
   * 
   * @param userName
   *          Name of user to be added
   * @param groupName
   *          Name of group user should be added to
   * @param pending
   *          true if user is added as pending user, false otherwise
   * @return true, if operation was successful, false otherwise
   */
  public boolean addUserToGroup(String userName, String groupName, boolean pending);

  /**
   * Removes a user from a group
   * 
   * @param userName
   *          name of user to remove from group
   * @param groupName
   *          name of group out of which user has to be removed
   * @return true, if operation was successful, false otherwise
   */
  public boolean removeUserFromGroup(String userName, String groupName);

  /**
   * Gets the user entity for a user name
   * 
   * @param usrName
   *          the user name
   * @return the user entity
   */
  public UserEntity getUserEntity(String usrName);

  /**
   * Gets the group entity for a group name
   * 
   * @param grpName
   *          the group name
   * @return the group entity
   */
  public GroupEntity getGroupEntity(String grpName);

  /**
   * Searches for a string in group names
   * 
   * @param srchString
   *          the string to be searches
   * @return the groups containing the string
   */
  public List<String> searchInGroups(String srchString);

  /**
   * Searches for a string at the beginning of preferences names
   * 
   * @param srchString
   *          the string to be searches
   * @return the preferences containing the string at the beginning of the word
   */
  public List<PreferenceEntity> searchInPreferences(String srchString);

  /**
   * Adds new preference to the database
   * 
   * @param preference
   *          the preference to persist
   * @return true if success, else false
   */
  public boolean persistNewPreference(PreferenceEntity preference);

  /**
   * Searches for a string in users
   * 
   * @param srchstring
   *          the string to search for
   * @return the list of user names
   */
  public List<String> searchInUsers(String srchstring);

  /**
   * searches for the preferences a user has selected
   * 
   * @param userName
   *          the name of the user
   * @return a list containing the user's preferences
   */
  public List<String> searchUserPreferences(String userName);

  /**
   * Searches for a group name and returns members of this group as a list.
   * 
   * @param groupName The name of the group
   * @return the list of members of the group
   */
  public List<String> searchGroupMembers(String groupName);

  /**
   * Gets the role entity object given the name
   * 
   * @param name the role name
   * @return the role entity object
   */
  public RoleEntity getRoleEntity(String name);

  /**
   * Checks if user with name 'name' is administrator
   * 
   * @param name name of the user
   * @return true if user is administrator, false otherwise
   */
  public boolean isContentAdmin(String name);
}